<template>
	<up-popup :round="24" @close="close1" :show="show" mode="bottom">
		<view class="login">
			<view class="city-phone">
				<view>用户隐私保护提示</view>
			</view>
			<view class="texts">
				<span>在你使用 企址易 支付之前，请仔细阅读</span>
				<br />
				<span style="color: #2AB4F5;" @click="gopage()">《{{title}}》</span>
				<br />
				<span>如你同意该指引，请点击“同意”开始使用本小程序。</span>
			</view>
			<view class="btnns">
				<view class="btnns1" @click="show=false">
					取消
				</view>

				<button class="logins1" open-type="getPhoneNumber" @getphonenumber="getUserPhoneNum">
					同意
				</button>

			</view>


		</view>
	</up-popup>
	<!-- <up-popup :show="show1" :closeOnClickOverlay="false" mode="bottom" borderRadius="24rpx 24rpx 0rpx 0rpx">
		<view class="botoommould" style="background: #fff;">
			<view class="centerebox">
				<view class="leftbox">
					<span>敏智云康</span>
				</view>
				<view class="texta">
					<span>获取您的头像昵称</span>
					<span> 获取用户头像、昵称、主要用于向用户提供辨识度的用户中心页面</span>
				</view>
				<view class="usertx">
					<view class="lablettitle">
						微信头像
					</view>
					<button class="righttex" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
						<image
							:src="userinfo1.avatar?userinfo1.avatar:_static('/images/static/微信图片_20250510120328.png')"
							mode="" class="rightteximg">
						</image>
					</button>

				</view>
				<view class="usernickname">
					<view class="lablettitle">
						微信昵称
					</view>
					<view class="labytetx">
						<form @submit="formSubmitInfoTap">
							<input type="nickname" v-model="userinfo1.nickname" @change="getNickname"
								placeholder="请输入昵称" maxlength="20" />
						</form>
					</view>
				</view>
				<button class="logins1" @click="save" style="margin-bottom: 50rpx;margin-top: 50rpx;">
					保存
				</button>

			</view>
		</view>
	</up-popup> -->
</template>

<script>
	import ulm, {
		$api
	} from '@/ulm';
	import {
		setToken,
		getToken
	} from '@/ulm/utils/auth';
	export default {
		data() {
			return {
				show: false,
				show1: false,
				flag: false,
				title: '',
				userinfo1: {
					nickname: '',
					avatar: '',
					show: false
				},
			}
		},
		created() {
			if (getToken()) {
				this.getuserinfo()
			}
			this.xieyi()
		},
		methods: {
			async xieyi() {
				const res = await $api['article']({
					id: 2
				})
				if (res.code == 1) {
					this.title = res.data.title
				}
			},
			close1() {
				this.show = false
			},
			gopage() {
				uni.navigateTo({
					url: '/sub_me/index/xieyi?id=' + 2
				})
			},
			async save() {
				if (!this.userinfo1.avatar || !this.userinfo1.nickname) {
					uni.showToast({
						title: '请补全头像或昵称',
						icon: 'none'
					})
					return
				}
				if (this.userinfo1.nickname.length > 15) {
					uni.showToast({
						title: '昵称不能超过15个字符',
						icon: 'none'
					})
					return
				}
				const res = await $api.userprofile({
					nickname: this.userinfo1.nickname,
					avatar: this.userinfo1.avatar,
				})
				if (res.code == 1) {
					uni.showToast({
						title: '保存成功',
						icon: 'none'
					})
					this.show1 = false
					this.$emit("updata", false)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			getNickname(e) {
				this.userinfo1.nickname = e.detail.value
			},
			DengLu() {
				this.show = true
			},

			// 获取微信头像
			onChooseAvatar(e) {
				var that = this
				uni.uploadFile({
					url: uploadSrc, //仅为示例，非真实的接口地址
					filePath: e.detail.avatarUrl,
					name: 'file',
					header: {
						token: uni.getStorageSync('token')
					},
					success: (uploadFileRes) => {
						that.userinfo1.avatar = JSON.parse(uploadFileRes.data).data.fullurl
					}
				});
				this.userinfo1.nickname = ''
				// 注意:这里拿到的头像url是个临时的路径,需要自行对头像进行上传处理,参考uni.upload()
			},
			close() {
				this.$refs.cityPhonePop1.close()
			},
			getUserPhoneNum(e) {

				if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
					return
				}
				let that = this
				console.log(e, 'eeeeeeeeeeeeeeeeeee');
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						let dataPhone = {
							code: loginRes.code,
							encryptedData: e.detail.encryptedData,
							iv: e.detail.iv,
							pid: 0,
							telcode: e.detail.code
						}
						that.shdnlogo(dataPhone)
					}
				});
			},
			async getuserinfo() {
				// const res = await $api.userinfo()
				// if (res.code == 1) {
				// 	if (res.data.avatar == '1' || !res.data.nickname) {
				// 		// this.show1 = true
				// 	}
				// }
			},
			shdnlogo(e) {
				let that = this
				$api.wxlogin({
					...e
				}).then(res => {
					if (res.code == '1') {
						let userinfo = res.data.userinfo
						setToken(userinfo.token)
						that.$emit("updata", false)
						that.show = false
						// this.getuserinfo()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-popup__content {
		background: none !important;
	}

	button {
		border: none !important;
		align-items: center;
		overflow: auto !important;
		background: none !important;
		background-color: none !important;
		background-size: 100% 138% !important;
		padding-left: 0 !important;
		padding-right: 0 !important;
		margin-left: 0rpx !important;
		-webkit-tap-highlight-color: none !important;
		overflow: hidden !important;

		&:after {
			background: none !important;
			border: none;
			background-color: none !important;
			display: none !important;
		}
	}

	.xk {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #86909C;
		display: flex;
		align-items: center;
		margin-top: 30rpx;

		image {
			width: 32rpx;
			height: 32rpx;
			margin-right: 16rpx;
		}
	}

	.btnns {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 62rpx;

		.logins1 {
			width: 328rpx !important;
			background: #2AB4F5 !important;
			color: #fff;
			font-size: 16px;
			border-radius: 8px;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			border: none;
			margin-right: 0 !important;

			&:after {
				border: none;
			}
		}

		.btnns1 {
			width: 328rpx;
			height: 90rpx;
			background: #F2F3F5;
			color: #1D2129;
			font-size: 32rpx;
			text-align: center;
			line-height: 90rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
		}
	}


	.buyunxu {
		width: 328rpx;
		height: 74rpx;
	}

	.login {
		width: 100%;
		background-color: #fff;
		padding: 20px 20rpx 0rpx 20rpx;
		box-sizing: border-box;
		border-radius: 48rpx 48rpx 0rpx 0rpx;
		z-index: 999;

		.texts {
			margin-top: 36rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #1D2129;
		}

		.city-phone {
			margin-bottom: 40rpx;

			view {
				font-size: 32rpx;
				font-weight: 600;
				// margin-bottom: 10px;
			}

			text {
				font-size: 14px;
				color: #999;
			}
		}

		.logins1 {
			background: #D0976F;
			color: #fff;
			font-size: 16px;
			border-radius: 8px;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			border: none;
			margin-right: 0 !important;

			&:after {
				border: none;
			}
		}
	}


	.botoommould {
		width: 100%;
		background: #F5F5F5;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		overflow: hidden;
	}

	::v-deep .u-popup__content {
		background: none !important;
	}

	.centerebox {
		width: 690rpx;
		margin: auto;
		margin-top: 50rpx;
	}

	.leftbox {
		display: flex;
		align-items: center;
	}

	.leftbox image {
		width: 51rpx;
		height: 51rpx;
		margin-right: 12rpx;
	}

	.leftbox span {
		font-family: PingFang SC-Regular;
		font-weight: 400;
		font-size: 30rpx;
		color: #151515;
		margin-left: 12rpx;
	}

	.righticon {
		width: 40rpx;
		height: 40rpx;
	}

	.top {
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		justify-content: space-between;
	}

	.texta {
		width: 100%;
		margin-top: 60rpx;
		display: flex;
		flex-direction: column;
	}

	.texta span:nth-child(1) {
		font-family: PingFang SC-Medium;
		font-weight: 500;
		font-size: 42rpx;
		color: #151515;
	}

	.texta span:nth-child(2) {
		font-family: PingFang SC-Medium;
		font-weight: 500;
		font-size: 26rpx;
		margin-top: 20rpx;
		color: #999999;
	}

	.phones {
		width: 100%;
		margin-top: 54rpx;
	}

	.Itemphone {
		width: 690rpx;
		height: 160rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin-bottom: 20rpx;
		text-align: center;
		line-height: 60rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.Itemphone .num {
		font-family: PingFang SC-Bold;
		font-weight: bold;
		font-size: 48rpx;
		color: #000000;
		margin-top: 39rpx;
	}

	.Itemphone .msg {
		font-family: PingFang SC-Regular;
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
	}

	.textr {
		font-family: PingFang SC-Medium;
		font-weight: 500;
		font-size: 30rpx;
		color: #666666;
		line-height: 160rpx;
	}

	.msgg {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 25rpx;
		margin-top: 54rpx;
		text-align: center;
		margin-bottom: 122rpx;
	}

	.usernickname {
		display: flex;
		align-items: center;
		margin-top: 60rpx;
	}

	.lablettitle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #666666;
	}

	.righttex {

		width: 88rpx;
		height: 88rpx;
		border-radius: 50%;
		position: relative;
		display: flex;
		border: none !important;
		align-items: center;
		overflow: auto !important;
		// background: $btn !important;
		background-color: none !important;
		background-size: 100% 138% !important;
		padding-left: 0 !important;
		padding-right: 0 !important;
		margin-left: 40rpx !important;
		-webkit-tap-highlight-color: none !important;
		margin-right: 0 !important;

	}

	.rightteximg {
		width: 88rpx;
		height: 88rpx;
		position: absolute;
	}

	.labytetx {
		font-family: PingFang SC-Bold;
		font-weight: bold;
		font-size: 30rpx;
		color: #151515;
		margin-left: 40rpx;
	}

	.usertx {
		display: flex;
		align-items: center;
		margin-top: 49rpx;
	}

	.arrow {
		width: 44rpx;
		height: 44rpx;
		margin-left: 398rpx;
	}

	.btnn {
		width: 360rpx;
		height: 78rpx;
		background: #8278FF;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		text-align: center;
		line-height: 78rpx;
		font-family: PingFang SC-Medium;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		margin: auto;
		margin-top: 116rpx;
		margin-bottom: 82rpx;
	}
</style>